package com.koron.order.common.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.bean.po.OrderLocationPo;
import com.koron.order.common.service.OrderLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工单工作地点表(OrderLocation)表控制层
 *
 * @author zhouj
 * @since 2022-05-17 10:08:38
 */
@Api(tags = "工单工作地点表(OrderLocation)")
@RestController
@RequestMapping("/orderLocation/")
public class OrderLocationController {

    @Autowired
    private OrderLocationService orderLocationService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改工单工作地点表")
    @PostMapping("insertOrUpdate")
    public Response<Integer> insertOrUpdate(@RequestBody OrderLocationPo orderLocation) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "insertOrUpdate", Integer.class, orderLocation));
    }

    @ApiOperation(value = "新增工单工作地点表")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody OrderLocationPo orderLocation) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "insert", Integer.class, orderLocation));
    }

    @ApiOperation(value = "批量新增工单工作地点表")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<OrderLocationPo> orderLocationList) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "insertBatch", Integer.class, orderLocationList));
    }

    @ApiOperation(value = "根据id更新工单工作地点表")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody OrderLocationPo orderLocation) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "update", Integer.class, orderLocation));
    }

    @ApiOperation(value = "根据id删除工单工作地点表")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询工单工作地点表")
    @GetMapping("queryById")
    public Response<OrderLocationPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "queryById", OrderLocationPo.class, id));
    }

    @ApiOperation(value = "不分页查询工单工作地点表列表")
    @GetMapping("queryList")
    public Response<List> queryList(OrderLocationPo queryVo) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "queryList", List.class, queryVo));
    }

    @ApiOperation(value = "分页查询工单工作地点表列表")
    @GetMapping("queryPageList")
    public Response<PageInfo> queryPageList(OrderLocationPo queryPo, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderLocationService, "queryPageList", PageInfo.class, queryPo, pageQuery));
    }

}
